//
//  ZoomViewController.m
//  CamH
//
//  Created by xqiu on 12-8-29.
//  Copyright (c) 2012年 ghu. All rights reserved.
//

#import "ZoomViewController.h"

@interface ZoomViewController ()

@end

@implementation ZoomViewController
@synthesize m_pSlider;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}	

-(void)touchRepeat
{
    CGFloat value = m_pSlider.value;
    if(bZoomIn == YES){
        value = value + 0.03;
    }else {
        value = value - 0.03;
    }
    if(value >=  m_pSlider.maximumValue){
        value =  m_pSlider.maximumValue;
    }if(value <= m_pSlider.minimumValue){
        value =  m_pSlider.minimumValue;
    }
    m_pSlider.value = value;
    [self.zoomDelegate valueChange:(value - fLastScale)];
    fLastScale = value;
}

- (IBAction)zoomInTouchDowm:(id)sender
{
    bZoomIn = YES;
    touchDownTimer = [NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval).03
                                                      target:self
                                                    selector:@selector(touchRepeat)
                                                    userInfo:nil
                                                     repeats:TRUE];
}

- (IBAction)zoomInAction:(id)sender
{
    [touchDownTimer invalidate];
}

- (IBAction)zoomOutTouchDowm:(id)sender
{
    bZoomIn = NO;
    touchDownTimer = [NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval).03
                                                      target:self
                                                    selector:@selector(touchRepeat)
                                                    userInfo:nil
                                                     repeats:TRUE];
}

- (IBAction)zoomOutAction:(id)sender
{
    [touchDownTimer invalidate];
}

- (IBAction)sliderAction:(id)sender
{
    UISlider *slider = (UISlider *)sender;
    CGFloat value = slider.value - fLastScale;
    if ([self.zoomDelegate respondsToSelector:@selector(valueChange:)])
        [self.zoomDelegate valueChange:value];
    fLastScale = slider.value;
}

- (void) setThumbValue:(CGFloat)value
{
    fLastScale = value;
    m_pSlider.value = value;
}

@end
